﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Search.aspx.cs" Inherits="AttendanceWebForm_LeaveData_Search" %>
<script runat="server">
    /* list */
    protected void gv_DataBinding(object sender, EventArgs e)
    {
        var sql = new StringBuilder();
        
        sql.AppendFormat(@"SELECT ld.* FROM LeaveData ld WHERE ld.OrgID IN ({0}) "
            , MyObj.JoinFormat(",", "'{0}'", RoleManager.Current.GetOrgForCurrentComp()));
        
        var dbparams = new List<DBParameter>();

        if (txtEmpID.Text.Length > 0)
        {
            sql.AppendFormat("AND EmpID = @EmpID ");
            dbparams.Add(new DBParameter("EmpID", txtEmpID.Text));
        }

        if (ddlYYMM.Text.Length > 0)
        {
            sql.AppendFormat("AND Year(LeaveStartDate) = Year(@LeaveDate) AND Month(LeaveStartDate) = Month(@LeaveDate) ");
            dbparams.Add(new DBParameter("LeaveDate", ddlYYMM.Value));
        }        
        
        var db = new DB("Attendance");
        var dt = db.Execute(sql.ToString(), dbparams.ToArray());

        (sender as DataBoundControl).DataSource = dt;
    }
    /* end of list */

    /* form */

    /* end of form */
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:PlaceHolder ID="plQuery" runat="server">
    <table>
        <tr>
            <td class="label">
                <asp:Localize ID="Localize2" runat="server" Text="<%$Resources: EmpData, EmpID %>"></asp:Localize>
            </td>
            <td class="text">
                <asp:TextBox ID="txtEmpID" runat="server"></asp:TextBox>
            </td>
            <td class="label">
                <asp:Localize ID="Localize1" runat="server" Text="<%$Resources: lblYYMM.Text %>"></asp:Localize>
            </td>
            <td class="text">
                <My:YYMM ID="ddlYYMM" runat="server" Optional="true"></My:YYMM>
            </td>
            <td class="text">
                <asp:Button ID="btnQuery" runat="server" Text="<%$Resources: Form, btnQuery %>" OnClick="btnQuery_Click" />
                <My:ClearButton ID="ClearButton1" runat="server"></My:ClearButton>
            </td>
        </tr>
    </table>
</asp:PlaceHolder>
    <My:MyGridView ID="gv" runat="server" OnDataBinding="gv_DataBinding" OnRowCommand="gv_ItemCommand"
        DataKeyNames="LeaveID">
        <Columns>
            <asp:TemplateField HeaderText="<%$Resources: LeaveData, EmpID   %>">
                <ItemTemplate>
                    <%#Eval("EmpID") %>
                    <%# LocManager.Current.GetText("EmpData", "EmpName", Eval("EmpID"))%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$Resources: LeaveData, OrgID   %>">
                <ItemTemplate>
                    <%# LocManager.Current.GetText("OrgData", "OrgName", Eval("OrgID")) %>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$Resources: LeaveData, LeaveType   %>">
                <ItemTemplate>
                    <%# CodeManager.Current.GetText("LeaveData", "LeaveType", Eval("LeaveType"))%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$Resources: LeaveData, LeaveStartDate   %>">
                <ItemTemplate>
                    <%#Eval("LeaveStartDate", "{0:yyyy/MM/dd HH:mm}")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$Resources: LeaveData, LeaveEndDate   %>">
                <ItemTemplate>
                    <%#Eval("LeaveEndDate", "{0:yyyy/MM/dd HH:mm}")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$Resources: LeaveData, Hours   %>">
                <ItemTemplate>
                    <%#Eval("Hours")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$Resources: Form, CreateDate   %>">
                <ItemTemplate>
                    <%#Eval("CreateDate")%>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="<%$Resources: Form, Status   %>">
                <ItemTemplate>
                    <%# CodeManager.Current.GetText("LeaveData", "Status", Eval("Status"))%>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </My:MyGridView>
</asp:Content>

